package aor2.components;

public class FlipFlopD extends FlipFlop {

	public FlipFlopD(boolean state, Signal d, Signal q) {
		super(state);
		this.d = d;
		this.q = q;
	}

	public FlipFlopD(Signal d, Signal q) {
		super(false);
		this.d = d;
		this.d.addDestinationElementIO(this);
		this.q = q;
		this.q.addSourceElementIO(this); // TODO PROVERITI!

	}

	Signal d, q;

	@Override
	public void in() throws FlipFlopException {
		if (d == null) {
			throw new FlipFlopException("Signal D not connected.");
		}
		state = d.isActive();
	}

	@Override
	public void out() throws FlipFlopException {
		if (q == null) {
			throw new FlipFlopException("Signal Q not connected.");
		}
		q.setActive(state);
	}

	public Signal getOut() {
		return q;
	}

}
